<template>
  <HomePanel title="热门品牌" sub-title="国际经典 品质保证">
    <template v-slot:right>
      <a
        @click="toggle = !toggle"
        href="javascript:;"
        class="iconfont icon-angle-left prev"
      ></a>
      <a
        @click="toggle = !toggle"
        href="javascript:;"
        class="iconfont icon-angle-right next"
      ></a>
    </template>
    <div class="box" ref="box">
      <transition 
        name="change"
        mode="out-in"
        :duration="{ enter: 500, leave: 700 }"
        leave-active-class="animate__animated animate__bounceOutLeft animate__fast"
        enter-active-class="animate__animated animate__bounceInRight"
      >
        <ul class="list" v-if="toggle">
          <li v-for="(item, index) in firstPage" :key="index">
            <RouterLink to="/">
              <img v-lazyload="item.picture" alt="" />
            </RouterLink>
          </li>
        </ul>
        <ul class="list" v-else>
          <li v-for="(item, index) in lastPage" :key="index">
            <RouterLink to="/">
              <img v-lazyload="item.picture" alt="" />
            </RouterLink>
          </li>
        </ul>
      </transition>
    </div>
  </HomePanel>
</template>

<script>
import HomePanel from "./home-panel";
import { findBrand } from "@/api/home.js";
import { ref } from "vue";
export default {
  name: "HomeBrand",
  components: { HomePanel },
  setup() {
    // 第一页的五个数据
    const firstPage = ref([]);
    // 第二页的五个数据
    const lastPage = ref([]);
    // 获取的10个数据
    const brands = ref([]);
    const toggle = ref(true);
    findBrand(10).then((res) => {
      brands.value = res.result;
      firstPage.value = res.result.slice(0, 5);
      lastPage.value = res.result.slice(5);
    });
    return {
      brands,
      toggle,
      firstPage,
      lastPage,
    };
  },
};
</script>

<style scoped lang='less'>
.iconfont {
  width: 20px;
  height: 20px;
  background: #ccc;
  color: #fff;
  display: inline-block;
  text-align: center;
  margin-left: 5px;
  background: @xtxColor;
  &::before {
    font-size: 12px;
    position: relative;
    top: -2px;
  }
  &.disabled {
    background: #ccc;
    cursor: not-allowed;
  }
}
.box {
  display: flex;
  width: 100%;
  height: 345px;
  overflow: hidden;
  padding-bottom: 40px;
  .list {
    width: 200%;
    display: flex;
    transition: all 1s;
    li {
      .hoverShadow ();
      margin-right: 10px;
      width: 240px;
      &:nth-child(5n) {
        margin-right: 0;
      }
      img {
        width: 240px;
        height: 305px;
      }
    }
  }
}
</style>
